Update TypeScript typings with generic type parameters (#1061)#10
Update TypeScript typings with generic type parameters (#1061)#10MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
Conversation
…ethods & AxiosResponse
Update TypeScript typings with generic type parameters
📝 WalkthroughWalkthroughThe Axios TypeScript type declarations are converted to support generics, enabling strongly-typed response data handling. Key interfaces ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@index.d.ts`:
- Around line 104-110: The delete and head method signatures in index.d.ts lack
generic type parameters; update the methods named delete and head to accept a
generic type parameter (e.g., <T = any>) and make their return types
AxiosPromise<T>, matching the pattern used by get/post/put/patch so callers can
specify the response type; modify the signatures for the delete and head
functions (the ones currently declared as delete(url: string, config?:
AxiosRequestConfig): AxiosPromise and head(url: string, config?:
AxiosRequestConfig): AxiosPromise) to include the generic and return
AxiosPromise<T>.
🧹 Nitpick comments (1)
index.d.ts (1)
113-116: Consider adding generic type parameters toAxiosStaticcallable signatures.The
AxiosStaticinterface's callable signatures on lines 114-115 returnAxiosPromisewithout a generic type parameter. For full consistency with the updated instance methods, these could also accept generics.♻️ Optional enhancement for callable signatures
export interface AxiosStatic extends AxiosInstance { - (config: AxiosRequestConfig): AxiosPromise; - (url: string, config?: AxiosRequestConfig): AxiosPromise; + <T = any>(config: AxiosRequestConfig): AxiosPromise<T>; + <T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; create(config?: AxiosRequestConfig): AxiosInstance;
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
index.d.tstest/typescript/axios.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/typescript/axios.ts (1)
index.d.ts (1)
AxiosResponse(47-53)
🔇 Additional comments (2)
index.d.ts (1)
47-48: Good addition of generic type parameters.The generic typing for
AxiosResponse<T = any>andAxiosPromise<T = any>is well-implemented with appropriate defaults for backward compatibility.Also applies to: 62-62
test/typescript/axios.ts (1)
100-137: Good demonstration of generic type usage.The test examples effectively validate the new generic typings by:
- Defining a
Userinterface with expected properties- Creating a typed handler
handleUserResponsethat accessesresponse.data.idandresponse.data.namewith type safety- Demonstrating generic usage across
get<User>,post<User>,put<User>, andpatch<User>methodsConsider adding examples for
instance.request<User>(config)to demonstrate generic usage on the request method as well.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>; | ||
| get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; | ||
| delete(url: string, config?: AxiosRequestConfig): AxiosPromise; | ||
| head(url: string, config?: AxiosRequestConfig): AxiosPromise; | ||
| post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | ||
| put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | ||
| patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | ||
| post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | ||
| put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | ||
| patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; |
There was a problem hiding this comment.
delete and head methods are missing generic type parameters.
The delete and head methods on lines 106-107 have not been updated with generic type parameters, unlike get, post, put, and patch. This creates an inconsistency where users cannot specify response types for these methods.
🔧 Proposed fix to add generics to delete and head
request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
- delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
- head(url: string, config?: AxiosRequestConfig): AxiosPromise;
+ delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
+ head<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>; | |
| get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| delete(url: string, config?: AxiosRequestConfig): AxiosPromise; | |
| head(url: string, config?: AxiosRequestConfig): AxiosPromise; | |
| post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | |
| put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | |
| patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise; | |
| post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>; | |
| get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| head<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; | |
| patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>; |
🤖 Prompt for AI Agents
In `@index.d.ts` around lines 104 - 110, The delete and head method signatures in
index.d.ts lack generic type parameters; update the methods named delete and
head to accept a generic type parameter (e.g., <T = any>) and make their return
types AxiosPromise<T>, matching the pattern used by get/post/put/patch so
callers can specify the response type; modify the signatures for the delete and
head functions (the ones currently declared as delete(url: string, config?:
AxiosRequestConfig): AxiosPromise and head(url: string, config?:
AxiosRequestConfig): AxiosPromise) to include the generic and return
AxiosPromise<T>.
PR_030
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.